package org.wmq.housewebadmin.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.wmq.housemodel.entity.Label;
import org.wmq.housemodel.entity.Result;
import org.wmq.housewebadmin.service.LabelService;

import java.util.List;

@RestController
@RequestMapping("admin/label")
@RequiredArgsConstructor
public class LabelController {
    private final LabelService labelService;

    @GetMapping("/list")
    public Result<List<Label>> getLabelList(@RequestParam(required = false) Integer labelType){
        return Result.ok(this.labelService.getList(labelType));
    }

    @PostMapping("saveOrUpdate")
    public Result<Void> saveOrUpdateLabel(@RequestBody Label label){
        return this.labelService.saveOrUpdate(label);
    }

    @DeleteMapping("/{id}")
    public Result<Void> deleteById(@PathVariable Long id){
        return this.labelService.deleteById(id) ? Result.ok() : Result.error("删除失败");
    }
}
